package cs.study.height.concurrent017;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class UseExecutors {

	public static void main(String[] args) {
		/*
		ExecutorService pool = Executors.newFixedThreadPool(10);//创建10固定的线程池
		底层实现
		new ThreadPoolExecutor(nThreads, nThreads,
				               0L, TimeUnit.MILLISECONDS,
				               new LinkedBlockingQueue<Runnable>());
		*/

		/*
		ExecutorService pool = Executors.newSingleThreadExecutor();//创建一个线程池
		底层实现
		new ThreadPoolExecutor(1, 1,
                               0L, TimeUnit.MILLISECONDS,
                               new LinkedBlockingQueue<Runnable>())
		*/

		/*
		ExecutorService pool = Executors.newCachedThreadPool();
		底层实现
		new ThreadPoolExecutor(0, Integer.MAX_VALUE,
                               60L, TimeUnit.SECONDS,
                               new SynchronousQueue<Runnable>())零容量的队列
		*/

		/*
		ExecutorService pool = Executors.newScheduledThreadPool(10);
		底层实现
		super(corePoolSize, Integer.MAX_VALUE,
			  0, NANOSECONDS,
			  new DelayedWorkQueue())带有延时的队列
		*/
		//以上四个方法底层本质都是实例化了一个ThreadPoolExecutor
		//通过实例ThreadPoolExecutor时传递的参数不同来实现不同功能的
		/*
		new ThreadPoolExecutor(
		int corePoolSize,	当前核心线程数
		int maximumPoolSize,最大线程数
		long keepAliveTime, 线程池里面的线程空闲时间
		TimeUnit unit,      keepAliveTime的时间单位
		BlockingQueue<Runnable> workQueue, 没有空闲的线程时，用于存放任务
		ThreadFactory threadFactory,
		RejectedExecutionHandler headler 拒绝执行任务
		) {....}
		*/
		//cache fixed single

	}
}
